﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Manager_System
{////////////////////////////////////////////////////还要增加GID
    public partial class add_ingot_process : Form
    {
        
        string type = "";
        string Id = "";
        string Interid = "";
        main_form form;
        public add_ingot_process(main_form form1)
        {
            type = "添加";
            InitializeComponent();
 
            form = form1;
        }
        public add_ingot_process(string interid ,string id, string potnum, string material, string weight, string target, string situation, main_form form1)
        {
           
             InitializeComponent();
             Interid = interid;//
            type = "修改";
            
            Id = id.Substring(0, 4) + "/" + id.Substring(4, 2) + "/" + id.Substring(6, 2);//
            steel_dt.Value = Convert.ToDateTime(Id);
            form = form1;//
            this.material_tb.Text = material;//
            weight_tb.Text = weight;//
            target_tb.Text = target;//

            potnum_tb.Text = potnum;//
            situation_tb.Text = situation;//
 
        }

        private void add_steel_Load(object sender, EventArgs e)
        {
            add_steel_bt.Text = type.ToString();
            steel_dt.Format = DateTimePickerFormat.Custom; //设置为显示格式为自定义
            steel_dt.CustomFormat = "yyyy-MM-dd";

           
                  this.add_steel_bt.Text = type;
             
        }

        private void add_steel_bt_Click(object sender, EventArgs e)
        {

            #region 添加/修改计划
            string sql = "";
            string ID = steel_dt.Text.Substring(0, 4) + steel_dt.Text.Substring(5, 2) + steel_dt.Text.Substring(8, 2);
            if (type.Equals("添加"))
            {
                sql = "insert into T_ingot_process (time,potnum,Material,weight,target,situation) values('" + ID + "','" +potnum_tb.Text + "','" + this.material_tb.Text + "','" + weight_tb.Text + "','" + this.target_tb.Text + "','"+situation_tb.Text+"')";
            }
            if (type.Equals("修改"))
            {
                sql = "update T_ingot_process set time='" + ID + "',potnum='" + potnum_tb.Text + "',material='" + material_tb.Text + "',weight='" + weight_tb.Text + "',target='"+target_tb.Text+"',situation='"+situation_tb.Text+"' where InterID='" + Interid + "'";
            }

            if (material_tb.Text.Trim() != String.Empty && potnum_tb.Text.Trim() != String.Empty && weight_tb.Text.Trim() != String.Empty && target_tb.Text.Trim() != String.Empty && situation_tb.Text.Trim() != String.Empty && steel_dt.Value.ToString() != String.Empty)
            {

                DBhelp db = new DBhelp();
                int rs = db.update(sql);
                if (rs == 1)
                {
                    MessageBox.Show(type.ToString() + "成功！");
                }
                else
                {
                    MessageBox.Show(type.ToString() + "失败！");
                }
                db.close();
        
                form.Refresh_ingot_process_LV("n");
            }
            else
            {
                MessageBox.Show("请输入相关数值！");
            }

            #endregion
        }

        private void close_bt_Click(object sender, EventArgs e)
        {

            this.Close();
        }
    }
}

